<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebSocket</title>
<script type="text/javascript">
	var socket;
	if(window.WebSocket){
		socket = new WebSocket("ws://localhost:8891/ws");
		socket.onmessage = function(event){
			var node = document.getElementById("responseText");
			node.value = node.value + "\n" + event.data;
		}
		
		socket.onopen = function(event){
			var node = document.getElementById("responseText");
			node.value = "Connect Start";
		}
		
		socket.onclose = function(event){
			var node = document.getElementById("responseText");
			node.value = node.value + "\n" + "Connect Close!";
		}
	}else{
		alert("Browser can't supported!");
	}
	
	function send(message){
		if(!window.WebSocket){
			return;
		}
		if(socket.readyState == WebSocket.OPEN){
			socket.send(message);
		}else{
			alert("Connect not yet open！");
		}
	}
</script>
</head>
<body>
	<form onsubmit="return false">
		<textarea name="message" style="width:400px;herght:200px"></textarea>
		<input type="button" value="发送数据" onclick="send(this.form.message.value)"/>
		<h3>服务器输出</h3>
		<textarea id="responseText" style="width:400px;herght:200px"></textarea>
		<input type="button" value="清空内容" onclick="javascript:document.getElementById('responseText').value=''"/>
	</form>

</body>
</html>
